package com.rattsoftware.client;

import com.extjs.gxt.ui.client.GXT;
import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.util.Theme;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.rattsoftware.client.controllers.CourseController;
import com.rattsoftware.client.controllers.CourseUnitController;
import com.rattsoftware.client.controllers.DepartmentController;
import com.rattsoftware.client.controllers.FacultyController;
import com.rattsoftware.client.controllers.HomePageController;
import com.rattsoftware.client.controllers.LoginController;
import com.rattsoftware.client.controllers.MainAppController;
import com.rattsoftware.client.controllers.NewEditCourseController;
import com.rattsoftware.client.controllers.NewEditCourseUnitController;
import com.rattsoftware.client.controllers.NewEditDepartmentController;
import com.rattsoftware.client.controllers.NewEditFacultyController;
import com.rattsoftware.client.controllers.NewEditStaffController;
import com.rattsoftware.client.controllers.NewEditUserController;
import com.rattsoftware.client.controllers.RoomController;
import com.rattsoftware.client.controllers.StaffController;
import com.rattsoftware.client.controllers.TimeTableController;
import com.rattsoftware.client.controllers.UserListController;
import com.rattsoftware.client.events.AppEvents;
import com.rattsoftware.client.service.AuthenticationServiceAsync;
import com.rattsoftware.client.service.CourseServiceAsync;
import com.rattsoftware.client.service.CourseUnitServiceAsync;
import com.rattsoftware.client.service.DepartmentServiceAsync;
import com.rattsoftware.client.service.FacultyServiceAsync;
import com.rattsoftware.client.service.RoleServiceAsync;
import com.rattsoftware.client.service.SettingServiceAsync;
import com.rattsoftware.client.service.StaffServiceAsync;
import com.rattsoftware.client.service.TimeTableServiceAsync;
import com.rattsoftware.client.service.UserService;
import com.rattsoftware.client.service.UserServiceAsync;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class webclient implements EntryPoint {
	public static final String LOGGED_IN_USER_NAME = "loggedInUser";
	public static final String USER_SERVICE = "userService";
	public static final String AUTHENTICATION_SERVICE = "authenticationService";
	public static final String ROLE_SERVICE = "roleService";
	public static final String SETTING_SERVICE = "settingService";

	public static final String COURSE_SERVICE = "courseService";
	public static final String COURSE_UNIT_SERVICE = "courseUnitService";
	public static final String FACULTY_SERVICE = "facultyService";
	public static final String DEPARTMENT_SERVICE = "departmentService";
	public static final String TIMETABLE_SERVICE = "timeTableService";
	public static final String STAFF_SERVICE = "staffService";
	public static final String ROOM_SERVICE = "roomService";
	
	/**
	 * This is the entry point method.
	 */
	@Override
	public void onModuleLoad() {

		GXT.setDefaultTheme(Theme.BLUE, true);

		// create the services
		UserServiceAsync userService = (UserServiceAsync) GWT
				.create(UserService.class);
		RoleServiceAsync roleService = RoleServiceAsync.Util.getInstance();
		SettingServiceAsync settingService = SettingServiceAsync.Util
				.getInstance();
		AuthenticationServiceAsync authenticationService = AuthenticationServiceAsync.Util
				.getInstance();
		FacultyServiceAsync facultyService = FacultyServiceAsync.Util.getInstance();
		DepartmentServiceAsync departmentService = DepartmentServiceAsync.Util.getInstance();
		CourseUnitServiceAsync courseUnitService = CourseUnitServiceAsync.Util.getInstance();
		CourseServiceAsync courseService = CourseServiceAsync.Util.getInstance();
		TimeTableServiceAsync timeTableService = TimeTableServiceAsync.Util.getInstance();
		StaffServiceAsync staffService = StaffServiceAsync.Util.getInstance();
		

		// save the services for global usage
		Registry.register(USER_SERVICE, userService);
		Registry.register(ROLE_SERVICE, roleService);
		Registry.register(SETTING_SERVICE, settingService);
		Registry.register(AUTHENTICATION_SERVICE, authenticationService);
		Registry.register(FACULTY_SERVICE, facultyService);
		Registry.register(DEPARTMENT_SERVICE, departmentService);
		Registry.register(COURSE_UNIT_SERVICE, courseUnitService);
		Registry.register(COURSE_SERVICE, courseService);
		Registry.register(TIMETABLE_SERVICE, timeTableService);
		Registry.register(STAFF_SERVICE, staffService);

		// create the dispatcher and register controllers
		Dispatcher dispatcher = Dispatcher.get();
		dispatcher.addController(new MainAppController());
		dispatcher.addController(new LoginController());
		dispatcher.addController(new HomePageController());
		dispatcher.addController(new UserListController());
		dispatcher.addController(new NewEditUserController(userService,
				roleService));
		dispatcher.addController(new StaffController());
		dispatcher.addController(new RoomController());
		
		dispatcher.addController(new TimeTableController());
		dispatcher.addController(new CourseController());
		dispatcher.addController(new FacultyController());
		dispatcher.addController(new DepartmentController());
		dispatcher.addController(new NewEditCourseUnitController());
		dispatcher.addController(new CourseUnitController());
		dispatcher.addController(new NewEditCourseController());
		dispatcher.addController(new NewEditFacultyController());	
		dispatcher.addController(new NewEditDepartmentController());	
		dispatcher.addController(new NewEditStaffController());
		
		dispatcher.dispatch(AppEvents.Login);

		GXT.hideLoadingPanel("loading");
	}
}
